import {
  exportUrl,
  getOrderTypeList,
  getCurrentWarehouseCode, getMaterialTypeList, getGoodsList, mesTmMaterialBrand,
} from "@/api/inbound/mesInTask"
import { checkStr } from "@/utils/judge"
import {getDict, getPostList, getPostListPage} from "@/api/common";
import {getOrderStatusList} from "@/api/order/mesProdOrder";
// 列表头按钮配置
export const operateList = [
  // {
  //   name: $i18n.t("common.add"),
  //   type: "primary",
  //   icon: "el-icon-circle-plus-outline",
  //   handleName: "add", // 点击时返回的标识
  //   auth: "auth:wms:wsmsInTask:add" //权限字段
  // },
]
// 行末按钮配置
export const rowConfig = [
  {
    name: "查看",
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", //点击时返回的标识
    auth: "auth:wms:wsmsInTask:edit", //权限字段,
    // disabled: (row) => row.isFinish === 'Y',
  }
]
// 搜索条件配置
export const searchConfig = {
  inline: true,
  formDesc: {
    orderNo: {
      type: "input",
      label: "入库单编码"
    },
    orderCode: {
      type: "input",
      label: "需求单编码"
    },
    goodsName: {
      type: "input",
      label: "物料号/名称"
    },
    brand: {
      type: "input",
      label: "品牌"
    },
    unit: {
      type: "input",
      label: "规格"
    },
    supplierName: {
      type: "input",
      label: "供应商"
    },
  }
}
var checkNum = (rule, value, callback) => {
  setTimeout(() => {
    var reg = /^\d+$/
    if (value && !reg.test(value)) {
      callback(new Error($i18n.t("wmsInTask.rule13")))
    } else {
      callback()
    }
  }, 100)
}
// 新增/删除表单配置
export const formDescDialog = {
  data() {
    const _this = this
    return {
      formDescDialog: {
        span: 24,
        isShowSubmitBtn: false,
        isShowBackBtn: false,
        labelPosition: "top",
        rules: {
          version: [{ validator: checkNum, trigger: ["blur", "change"] }]
        },
        formDesc: {
          mesKtInTaskDetailVos: {
            type: "table-editor",
            label: "物料列表",
            layout: 24,
            attrs: {
              // 上方,按钮,render
              topBtnRender: (h, solt) => {
                return (
                  <el-button
                    type="primary"
                    onClick={() => {
                      _this.addList()
                    }}>
                    {$i18n.t("common.add2")}
                  </el-button>
                )
              },
              isShowAdd: false,
              isShowDelete: true,
              extraBtns: [
                {
                  text: "入库",
                  attrs: {
                    type: "text",
                  },
                  style: {
                    color: '#6caaf5'
                  },
                  click(scope) {
                    _this.viewPic(scope.row)
                  }
                },
              ],
              // 表格列
              columns: [
                {
                  // el-table-column 的属性
                  type: "index",
                  width: 50
                },
                {
                  // el-table-column 的属性
                  prop: "goodsCode",
                  label: "物料编码",
                  showOverflowTooltip: true,
                  // width: 130
                },
                {
                  prop: "goodsName",
                  label: "物料名称",
                  showOverflowTooltip: true,
                },
                {
                  prop: "brand",
                  label: "品牌",
                  width: 180,
                  showOverflowTooltip: true,
                  content: {
                    attrs: ({ row }) => {
                      return {
                        // disabled: row.id!== '',
                      };
                    },
                    type: "el-select",
                    optionProp: {
                      value: "modelingCode",
                      label: "modelingName"
                    },

                  },

                },
                {
                  prop: "planAmount",
                  label: "计划数量",
                },
                {
                  prop: "realAmount",
                  label: "库存数量",
                },
                {
                  prop: "accountingAmount",
                  label: "入库数量",
                  width: 180,
                  // 当有 content 属性时, 可以指定相应的组件
                  content: {
                    // type 可以为全局注册的组件名或者组件引用
                    type: "el-input-number",
                    // attrs 是组件的属性
                    attrs: {
                      placeholder: "请输入入库数量",
                      min: 0,
                      controlsPosition: "right",
                    },
                  },
                },
                {
                  prop: "packUnitShow",
                  label: "入库单位",
                },
                {
                  prop: "materialTypeStr",
                  label: "物料类型",
                  width: 170,
                  content: {
                    attrs: ({ row }) => {
                      return {
                        disabled: row.id !== '',
                      };
                    },
                    type: "el-select",
                    options: [
                      {text: "原厂件", value: "原厂件" },
                      { text: "品牌件", value: "品牌件" },
                      { text: "其他", value: "其他" },
                      { text: "拆车件", value: "拆车件" },
                    ],
                  },
                },
                {
                  prop: "supplierName",
                  label: "供应商名称",
                  showOverflowTooltip: true,
                  width: 220,
                  content: {
                    type: "el-select",
                    options: async (data) => {
                      console.log('??')
                      const list = await getPostList()
                      return list.data.result
                    }
                  },
                },
              ],
            }
          }
        }
      }
    }
  },
  methods: {
    addList() {
      if(!this.formDataDialog.vinCode){
        this.$message.error('请先选择车辆');
        return;
      }
      this.goodsDialogVisible = true
      this.otherParam={
        vinCode: this.formDataDialog.vinCode
      }
      console.log(this.formDataDialog,'shenmjoi')
    }
  }
}
export const editTableRowConfig = [
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    handleName: "delete" //点击时返回的标识
  }
]
export const editTableFormDesc = {
  span: 24,
  isShowSubmitBtn: false,
  isShowBackBtn: false,
  positionLabel: "right",
  rules: {
    version: [{ validator: checkNum, trigger: ["blur", "change"] }]
  },
  formDesc: {
    warehouseCode: {
      type: "select",
      label: $i18n.t("common.warehouseCode"),
      required: true,
      prop: {
        value: "modelingCode",
        text: "modelingName"
      },
      options: async (data) => {
        const list = await getCurrentWarehouseCode()
        return list.data.result
      }
    },
    orderType: {
      type: "select",
      label: $i18n.t("wmsInTask.orderType"),
      layout: 6,
      required: true,
      prop: {
        value: "value",
        text: "description"
      },
      options: async (data) => {
        const list = await getOrderTypeList()
        return list.data.result
      }
    },
    planTime: {
      type: "datetime",
      label: $i18n.t("wmsInTask.planTime"),
      layout: 6,
      required: true,
      attrs: {
        valueFormat: "yyyy-MM-dd HH:mm:ss"
      }
    },
    // actualTime: {
    //   type: "datetime",
    //   label: $i18n.t('wmsInTask.actualTime'),
    //   layout: 6,
    //   required: false,
    //   attrs: {
    //     valueFormat: "yyyy-MM-dd HH:mm:ss",
    //   },
    // },
    // qualityInspectionStatus: {
    //   type: "select",
    //   label: "质检状态",
    //   layout: 6,
    //   required: false,
    //   prop: {
    //     value: "value",
    //     text: "description",
    //   },
    //   options: async (data) => {
    //     const list = await getQualityInspectionStatusList();
    //     return list.data.result;
    //   },
    // },
    // qualityInspectionTime: {
    //   type: "datetime",
    //   label: "质检时间",
    //   layout: 6,
    //   required: false,
    //   attrs: {
    //     valueFormat: "yyyy-MM-dd HH:mm:ss",
    //   },
    // },
    // owner: {
    //   type: "input",
    //   label: "货主",
    //   layout: 6,
    //   required: false,
    // },
    // version: {
    //   type: "input",
    //   label: "版本",
    //   layout: 6,
    //   required: false,
    // },
    remark: {
      type: "input",
      label: $i18n.t("common.remark"),
      layout: 6,
      required: false
    }
    // supplierCode: {
    //   type: "select",
    //   label: "供应商",
    //   layout: 6,
    //   required: false,
    //   prop: {
    //     value: "supplierCode",
    //     text: "supplierName",
    //   },
    //   options: async (data) => {
    //     const list = await getSupplier();
    //     return list.data.result;
    //   },
    // },
  }
}
